$(document).ready(function(){
		$(".masker").click(function(){
			$("#login").hide();
			$(".masker").hide();
		});
		$(".login").click(function(){
			var username = $("#name").val();
			var password = $("#password").val();
			if(username==''){
				swal("OMG!", "客官，这家伙忘记填名字了!!!", "error");
			}
			if(password==''){
				swal("OMG!", "客官，这家伙忘记写密码了!!!", "error");
			}
			$.ajax({
			    url: "/login.html",
			    type: "POST",
			    data: {username: username, password: password},
			    dataType: "json",
			    success: function(msg) {
			        if (msg.code == 200) {
			            swal("Good!", msg.msg, "success");
						$("#login").hide();
						$(".masker").hide();
						setTimeout(function(){
							window.location.reload();
						},1000);
			        } else {
			            swal("OMG!", msg.msg, "error");
			        }
			    },
			    error: function(xhr, status, error) {
						swal("OMG!", msg.msg, "error");
			    }
			});
			
		});	

		//zhuc
		$(".reg").click(function(){
			var username = $("#nickname").val();
			var password = $("#pwd").val();
			if(username==''){
				swal("OMG!", "客官，这家伙忘记填名字了!!!", "error");
			}
			if(password==''){
				swal("OMG!", "客官，这家伙忘记写密码了!!!", "error");
			}
			$.ajax({
			    url: "/reg.html",
			    type: "POST",
			    data: {username: username, password: password},
			    dataType: "json",
			    success: function(msg) {
			        if (msg.code == 200) {
			           swal("Good!", msg.msg, "success");
						$("#reg").hide();
						$(".masker").hide();
						setTimeout(function(){
							window.location.reload();
						},1000);
			        } else {
			            swal("OMG!", msg.msg, "error");
			        }
			    },
			    error: function(xhr, status, error) {
					swal("OMG!", msg.msg, "error");
			    }
			});
			
		});

	//访问
	function gohome(uid){
		var session=$(".session").val();
		if(session==''){
			swal("OMG!", "客官，这家伙忘记登录了!!!", "error");
			setTimeout(function(){
				$(".masker").show();
				$("#login").show();
			},2000);
			return false;
		}
		if(typeof(uid) == 'undefined'){
			swal("OMG!", "客官，这家伙拒绝你的访问!!!", "error");
			return false;
		}
		$.ajax({
			url: "/visit.html",
			type: "POST",
			data: {my_id: session, author_uid: uid},
			dataType: "json",
			success: function(msg) {
				if (msg.code == 200) {
					window.open('/home/' + uid + '.html', '_blank');
				} else {
					swal("OMG!", msg.msg, "error");
				}
			},
			error: function(xhr, status, error) {
				swal("OMG!", msg.msg, "error");
			}
		});
	}
		
	});